<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
%>

<jsp:include page="/comm/header.jsp"></jsp:include>
<link href="<%=path%>/css/message.css" type="text/css" rel="stylesheet"/>
<script src="<%=path%>/script/message.js"></script>
<style>
html,body{height:100%;}
body,div,h2{margin:0;padding:0;}
body{font:12px/1.5 Tahoma;}
center{padding-top:10px;}
#moverlay{position:absolute;top:0;left:0;width:100%;_width:2000px;height:100%;_height:2000px;background:#666;opacity:0.5;filter:alpha(opacity=50);display:none;z-index:998;
position:fixed!important;/*FF IE7*/
position:absolute;/*IE6*/_margin-left:-240px;
_top:       expression(eval(document.compatMode &&
            document.compatMode=='CSS1Compat') ?
            documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
            document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/}
#mwin{position:absolute;top:35%;left:48%;width:500px;height:200px;background:#fff;border:2px solid #a00000;display:none;z-index:999;
left:50%;
top:50%;
margin-left:-150px!important;/*FF IE7 该值为本身宽的一半 */
margin-top:-60px!important;/*FF IE7 该值为本身高的一半*/
margin-top:0px;
position:fixed!important;/* FF IE7*/
position:absolute;/*IE6*/
_top:       expression(eval(document.compatMode &&
            document.compatMode=='CSS1Compat') ?
            documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 :/*IE6*/
            document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/}

h2{font-size:12px;height:18px;text-align:right;background:#A10;border-bottom:0px solid #f90;padding:5px;cursor:move;}
h2 span{color:#f90;cursor:pointer;background:#fff;border:0px solid #f90;padding:0 0px;}

</style>
 <div class="clear"></div>
<!--第1部分开始  --> 
    <div class="wrap1">
    	<div class="blank1"></div>
        
<!--选项卡开始--> 	
<div id="mainTabbox">
	<jsp:include page="../tabboxhead3.jsp"/>
 
 
 	<div id="conten">
 		<div class="tab_show" id="con_tabmy_1">
  
<jsp:include page="left.jsp"></jsp:include>
<div class="wrap_left">
	<div class="wrap_m2">
    
	   <div class="wrap_m2_cont">
       
           <jsp:include page="top.jsp"></jsp:include>   

        <div class="my04">
        	<div class="my04_tt">我收到的消息</div>
            <div class="my04_cont" >
            	<s:if test="totalSize == 0">
            		暂无消息
            	</s:if>
            	<s:else>
            		<ul id="faq">
            			<div class="message_outside">
            				<s:form id="delForm" action="delMessagesByBuyer" method="post">
								<s:hidden name="read" />
								<input type="hidden" name="userType" value="2" />
		            			<s:iterator value="messageList" id="message">
				            		<li>
									  	<div class="wrap_left">
									  		<span class="show_checkbox">
									  	    	<input type="checkbox" name="smids" value="<s:property value='smid' />"  />
									  	  	</span>
									  	</div>
			  	   				 		<div class="wrap_right">
				  	    					<span class="show_content">
				    							<dl>
				     	 							<dt smid="<s:property value='smid' />" read="<s:property value='read' />" reply_tag="<s:property value='replyTag' />" style="cursor:pointer">
				     	 								<s:if test="read == 0 || replyTag == 2">
				     	 									<s:property value="title" />&nbsp;&nbsp;&nbsp;&nbsp;来自：<s:property value="senderName" />,<s:date name="createtime" format="yyyy-MM-dd HH:mm:ss"/>
				     	 									
				     	 								</s:if>
				      									<s:else>
				      										<span class="span_read_behind">
				     	 										<s:property value="title" />&nbsp;&nbsp;&nbsp;&nbsp;来自：<s:property value="senderName" />,<s:date name="createtime" format="yyyy-MM-dd HH:mm:ss"/>
				     	 									</span>
				      									</s:else>
				       								</dt>
				      								<dd>
				      									<s:iterator value="replyMessages" status="st">
				      										<s:if test="sender == #session.user.userid">
				      										    <li class="span_mine">
				      												我的回复：<s:property value="content" /><br/>
				      												<div class="span_msg"><s:date name="createtime" format="yyyy-MM-dd HH:mm:ss" /></div>
				      											</li>
				      										</s:if>
				      										<s:else>
				      											<li>
					      											<s:property value="senderName"/>：<s:property value="content" /><br/>
					      											<div class="span_msg"><s:date name="createtime" format="yyyy-MM-dd HH:mm:ss" /></div>
					      											<s:if test="#st.index == 0">
					      												<div class="span_reply"><a href="javascript:replyMessage(<s:property value='#message.smid'/>,<s:property value='smid' />, <s:property value='sender' />);">回复</a></div>
					      											</s:if>
																</li>
				      										</s:else>
				      									</s:iterator>
				      								</dd>
				      							</dl>
				      						</span>
				      					</div>
				      				</li>
		            			</s:iterator>
		            			<br/>
	            			</s:form>
  							<div class="wrap_left">
  								<span class="show_selectall">
  									<input type="checkbox" id="del" name="del" onclick="javascript:selectAll();" />全选    <span class="show_del"><a href="javascript:delMessages()">删除</a></span>
  								</span>
  							</div>
            			</div>
            		</ul>
            	</s:else>
            </div>
            <!--页码开始-->
			<div class="page_box">
				<div class="pagewrap">
					<div class="page">
	    				<s:if test="totalSize > 0">
							<ul>
								<s:if test="superPage == 1">
									<li>首页</li>
									<li>上一页</li>
								</s:if>
								<s:else>
									<s:url id="firstPage" action="inituser">
										<s:param name="superPage" value="1" />
										<s:param name="read" value="read" />
									</s:url>
									<s:url id="prevPage" action="inituser">
										<s:param name="superPage" value="superPage - 1" />
										<s:param name="read" value="read" />
									</s:url>
									<li><s:a href="%{firstPage}">首页</s:a></li>
									<li><s:a href="%{prevPage}">上一页</s:a></li>
								</s:else>
								<s:iterator value="pageList" status="st">
									<s:if test="pageNumber == '...'">
										<li><s:property value='pageNumber' /></li>
									</s:if>
									<s:elseif test="choose">
										<li class="thisclass"><s:property value='pageNumber' /></li>
									</s:elseif>
									<s:else>
										<s:url id="page#st.index" action="inituser">
											<s:param name="superPage" value="pageNumber" />
											<s:param name="read" value="read" />
										</s:url>
										<li><s:a href="%{page#st.index}"><s:property value='pageNumber' /></s:a></li>
									</s:else>
								</s:iterator>
								<s:if test="superPage == totalPage">
									<li>下一页</li>
									<li>末页</li>
								</s:if>
								<s:else>
									<s:url id="nextPage" action="inituser">
										<s:param name="superPage" value="superPage+1" />
										<s:param name="read" value="read" />
									</s:url>
									<s:url id="lastPage" action="inituser">
										<s:param name="superPage" value="totalPage" />
										<s:param name="read" value="read" />
									</s:url>
									<li><s:a href="%{nextPage}">下一页</s:a></li>
									<li><s:a href="%{lastPage}">末页</s:a></li>
								</s:else>
								<li><span class="pageinfo">共 <strong><s:property value='totalPage' /></strong>页<strong><s:property value='totalSize' /></strong>条
								</span></li>

							</ul>
						</s:if>
					</div>
				</div>

			</div>
			<!--页码结束 -->
		    <div class="blank1"></div>
        </div>  
       </div>
        

    
    </div>
</div>
<div class="clear"></div>
        
        <!--内容结束-->

 		</div>
 	
 	</div>
 </div>
<!--选项卡结束-->         
             
      </div>

    </div>

<jsp:include page="/comm/bottom.jsp"></jsp:include>
</body>
</html>
<script>
var curUserId = "<s:property value='#session.user.userid' />";
var lastCheckId = 0;
var _receiverId = 0;
var _replyId = 0;
var _smid = 0;
var lastFaqClick=null;
$(window).load(function(){
	var faq=document.getElementById("faq");
	  var dls=faq.getElementsByTagName("dl");
	  for (var i=0,dl;dl=dls[i];i++){
	    var dt=dl.getElementsByTagName("dt")[0];//取得标题
	     dt.id = "faq_dt_"+(Math.random()*100);
	     dt.onclick=function(){
	       var p=this.parentNode;//取得父节点
	        if (lastFaqClick!=null&&lastFaqClick.id!=this.id){
	          var dds=lastFaqClick.parentNode.getElementsByTagName("dd");
	          for (var i=0,dd;dd=dds[i];i++)
	            dd.style.display='none';
	        }
	        lastFaqClick=this;
	        var dds=p.getElementsByTagName("dd");//取得对应子节点，也就是说明部分
	        var tmpDisplay='none';
	        if (gs(dds[0],'display')=='none')
	          tmpDisplay='block';
	        for (var i=0;i<dds.length;i++)
	          dds[i].style.display=tmpDisplay;
	        
	        var read = this.getAttribute("read");
	        var smid = this.getAttribute("smid");
	        var replyTag = this.getAttribute("reply_tag");
	        if (read == 0 || replyTag == 2) {
	        	var html = this.innerHTML;
	        	this.setAttribute("read", 1);
	        	this.setAttribute("reply_tag", 0);
				var newHtml = "<span class='span_read_behind'>";
				newHtml += html;
				newHtml += "</span>";
				this.innerHTML = newHtml;
	        	$.ajax({
	    			url:'alreadyReadByBuyer.htm',
	    			type:'post',
	    			data:{"smid":smid},
	    			success:function(json) {
	    				
	    			}
	    		});	
	        }
	      }
	  }
	
	$("#sendmsg").click(function(){
		sendMsg();
	});
	
	var oWin = document.getElementById("mwin");
	var oLay = document.getElementById("moverlay");	
	var oClose = document.getElementById("mclose");
	var oH2 = oWin.getElementsByTagName("h2")[0];
	var bDrag = false;
	var disX = disY = 0;
	oClose.onclick = function ()
	{
		oLay.style.display = "none";
		oWin.style.display = "none";
		
	};
	oClose.onmousedown = function (event)
	{
		(event || window.event).cancelBubble = true;
	};
	oH2.onmousedown = function (event)
	{		
		var event = event || window.event;
		bDrag = true;
		disX = event.clientX - oWin.offsetLeft;
		disY = event.clientY - oWin.offsetTop;		
		this.setCapture && this.setCapture();		
		return false;
	};
	document.onmousemove = function (event)
	{
		if (!bDrag) return;
		var event = event || window.event;
		var iL = event.clientX - disX;
		var iT = event.clientY - disY;
		var maxL = document.documentElement.clientWidth - oWin.offsetWidth;
		var maxT = document.documentElement.clientHeight - oWin.offsetHeight;		
		iL = iL < 0 ? 0 : iL;
		iL = iL > maxL ? maxL : iL; 		
		iT = iT < 0 ? 0 : iT;
		iT = iT > maxT ? maxT : iT;
		
		oWin.style.marginTop = oWin.style.marginLeft = 0;
		oWin.style.left = iL + "px";
		oWin.style.top = iT + "px";		
		return false;
	};
	document.onmouseup = window.onblur = oH2.onlosecapture = function ()
	{
		bDrag = false;				
		oH2.releaseCapture && oH2.releaseCapture();
	};
});



function selectAll() {
	if ($("#del").attr("checked")) {
		$("[name=smids]").attr("checked", true);
	}
	else {
		$("[name=smids]").attr("checked", false);
	}
}

function delMessages() {
	if ($("[name=smids]:checked").length == 0) {
		alert("请选择一条消息。");
		return;
	}
	$("#delForm").submit();
}

function replyMessage(smid, replyid, receiver) {
	$("#content").val("");
	$("#smid").val(smid);
	$("#replyId").val(replyid);
	$("#receiver").val(receiver);
	$("#moverlay").show();
	$("#mwin").show();
}

var sendMsg = function(){
	var content = $("#content").val();
	content = $.trim(content);
	$("#content").val(content);
	if(!content){
		$("#mmsg").html("<font color='red'>发送内容不能为空，请重新输入！</font>");
		return;
	}else{
		if(content.length>300){
			$("#mmsg").html("<font color='red'>发送内容不能超过300个字符！</font>");
			return;
		}
		$("#sendMsg").submit();
	}
};
</script> 
<div id="moverlay"  style="display: none"></div>
<div id="mwin" style="display: none"><h2><span id="mclose">×</span></h2>
	<div class="reg_main">
		<s:form id="sendMsg" action="replyMsgByBuyer" method="post">
		<input type="hidden" id="smid" name="smid" />
		<input type="hidden" id="replyId" name="replyId" />
		<input type="hidden" id="receiver" name="receiver" />
		<s:hidden name="read" />
		<div id="mmsg" align="center"></div>
		<li><textarea id="content" name="content" rows="4" cols="80"></textarea></li>
        <li><div id="button" class="but_submit"><span style=" margin-left:70px"><a style="cursor:pointer" id="sendmsg">发送私信</a></span></div></li>
       	</s:form>
    </div>
</div>